package ch09.d1;

import java.util.Objects;

public class Student implements Comparable<Student> {
    String name;
    int score;
    String tel;
    String address;

    public Student(String name, int score, String tel, String address) {
        this.name = name;
        this.score = score;
        this.tel = tel;
        this.address = address;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", score=" + score +
                ", tel='" + tel + '\'' +
                ", address='" + address + '\'' +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        System.out.println("equals");
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return score == student.score && Objects.equals(name, student.name) && Objects.equals(tel, student.tel) && Objects.equals(address, student.address);
    }

    @Override
    public int hashCode() {
        System.out.println("hashCode");
        return Objects.hash(name, score, tel, address);
    }

//    String 比较两个字符串的大小 0 正数  负数
    //比较两个Student对象的大小
    //compareTo 比较的规则，自己指定的
    @Override
    public int compareTo(Student o) {
        System.out.println("compareTo:"+this.name+" 和 "+o.name+" 比较");
        //按照分数比较
        //this o
        return -this.score+o.score;
    }
}
